/* eslint-disable react-hooks/rules-of-hooks */
/*
 * @Author: mylesshie@gmail.com
 * @Date: 2020-07-14 15:19:14
 * @LastEditors: mylesshie@gmail.com
 * @LastEditTime: 2020-08-15 21:54:11
 * @description:
 */

import React, { useCallback, useEffect, useState } from 'react'
import { useDispatch } from 'react-redux'
import { WebView } from 'react-native-webview'
import { FlatList, SafeAreaView, Text, StatusBar } from 'react-native'
import EmptyList from '@/components/EmptyList'
import MessageItem from '@/components/MessageItem'
import styles from './styles'
import * as userActions from '@/actions/user'

import ScrollableTabView, { DefaultTabBar, ScrollableTabBar } from 'react-native-scrollable-tab-view'

const mineActivity = props => {
  const dispatch = useDispatch()
  // const [commentList, setCommentList] = useState([])
  // const [pageNum, setPageNum] = useState(1)
  // const [isRefreshing, setIsRefreshing] = useState(false)
  // const [pageEnd, setPageEnd] = useState(false)
  // const pageSize = 20
  const [webUrl, setWebUrl] = useState('')

  // const getList = useCallback(() => {
  //   dispatch(userActions.getMessages(pageNum, pageSize)).then(res => {
  //     setIsRefreshing(false)
  //     if (pageNum === 1) {
  //       setCommentList(res.list)
  //     } else {
  //       setCommentList(commentList.concat(res.list))
  //     }
  //     setPageEnd(res.total <= res.pageNum * res.pageSize)
  //   })
  // }, [dispatch])

  // useEffect(() => {
  //   getList()
  // }, [pageNum, pageSize])

  const _goDetail = async () => {
    let loginData = {}
    try {
      loginData = await global.storage.load({ key: 'loginState' })
      // return
    } catch (err) {
      // loginData = {}
    }

    // console.log('22222222')

    // console.log(JSON.stringify(loginData.uid))
    // console.log(JSON.stringify(loginData.token))
    // // console.log(testId)
    // console.log('2222222')
    return loginData



  }



  // global.storage.load({ key: 'loginState' }).then(res => {
  //   if (res.token) {
  //     // console.log('12312312312312312312')
  //     // console.log(res.token);
  //     // console.log(res.uid);
  //     let data = {
  //       userToken: res.token,
  //       userId: res.uid,


  //     };
  //     global.usertokenI = res.token
  //     global.userIdI = res.uid

  //     // this.web && this.web.postMessage('dasdasdas');//发送消息到H5
  //     // this.web && this.web.postMessage(JSON.stringify(data));//发送消息到H5

  //     // dispatch(userActions.getUserInfo())
  //   }
  // })


  // const testId = encodeURIComponent(global.userIdI)
  _goDetail().then((data) => {
    console.log('1111111111')

    console.log(data.token)
    // console.log('==')
    // console.log(data.token)
    let tk = encodeURIComponent(data.token)
    // let tk = data.token
    // setWebUrl('http://192.168.110.205:8080?' + 'id=' + JSON.stringify(data.uid) + 'token=' + tk)
    let url = 'https://wap.sctynews.cn/h5/index.html/' + 'id=' + JSON.stringify(data.uid) + 'token=' + data.token + '#/pages/eventList/index'
    // let url = 'http://192.168.110.205:8080/' + 'id=' + JSON.stringify(data.uid) + 'token=' + data.token + '#/pages/eventList/index'
    // let url = 'http://192.168.110.205:8080/' + 'id=5' + 'token=CyeYwxjpKG55%2Fqakaihrzy1Rr6nhQrJO5cPCv87FEmHvCCM1i0NEiYGImxb98Jgs%2BfTYCq9qK54%3D' + '' + '#/pages/eventList/index'
    setWebUrl(url)
    console.log(webUrl)
    console.log('1111111111')
  })

  // const testId2 = "123231"

  return (
    <>
      <StatusBar
        barStyle="dark-content"
        backgroundColor="transparent"
        translucent={true}
      />
      <WebView

        // source={{ uri: 'http://139.155.248.30:8002/h5/index.html#/' }}

        source={{ uri: webUrl }}
        style={styles.webview}
        useWebKit={true}
        startInLoadingState={true}
        onMessage={this._onMessage}
        javaScriptEnabled={true}

        // onLoadEnd={_onLoadEnd}
        allowsInlineMediaPlayback={true}
      />



      {/* </SafeAreaView> */}
    </>
  )
}

export default mineActivity
